package com.easy.dn.ui.main.model;

import com.easy.dn.bean.JobAddressBean;
import com.easy.dn.bean.ListBean;
import com.easy.dn.ui.main.contract.AddressTypeContract;
import com.easy.dn.utils.DnUtils;

import java.util.List;
import java.util.Map;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 丁宁
 * on 2017/7/21.
 */

public class AddressTypeModel implements AddressTypeContract.Model {

    @Override
    public Observable<ListBean> getAddressList(final List<JobAddressBean> mSelect) {
        return Observable.create(new Observable.OnSubscribe<ListBean>() {
            @Override
            public void call(Subscriber<? super ListBean> subscriber) {
//                DnUtils.getAddressList();
                ListBean<JobAddressBean> listBean = new ListBean<>();
                List<JobAddressBean> addressList = DnUtils.getAddressList();
                for (JobAddressBean addressBean : addressList) {
                    for (JobAddressBean selectBean : mSelect) {
                        if (selectBean.getName().equals(addressBean.getName())){
                            addressBean.setIsChecked(true);
                        }
                    }
                }
                listBean.setData(addressList);
                subscriber.onNext(listBean);
                subscriber.onCompleted();
            }
        }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io());
    }

    @Override
    public Observable<ListBean> getSelectData(Map<String, JobAddressBean> mSelect, String filterStr) {
        return null;
    }
}
